package com.example.dao.Impl;

import com.example.dao.EntDao;
import com.example.pojo.Ent;
import com.example.util.JdbcUtil;

import java.sql.ResultSet;


/***
 * 数据库操作中关于商品信息的实现类
 * @return
 */
public class EntDaoImpl implements EntDao {


    /**
     * 查询所有商品信息的方法
     * @return
     */
    @Override
    public ResultSet EntAll() {
        String sql = "select * from enterpeiseTalent";
        Object[] objects = new Object[0];
        ResultSet data = JdbcUtil.getData(sql, objects);
        return data;
    }

    /**
     * 通过id来删除商品信息的方法
     * @return
     */
    @Override
    public int EntDel(int id) {
        String sql = "delete from enterpeiseTalent where id = ?";
        Object[] objects = {id};
        int i = JdbcUtil.CRUData(sql, objects);
        return i;
    }


    /**
     * 增加商品信息的方法
     * @return
     */

    @Override
    public int EntAdd(Ent ent) {
        String sql = "insert into enterpeiseTalent " +
                "(name,workingLife,personalProfile,graduateSchool) value (?,?,?,?)";
        Object[] objects = new Object[4];
        objects[0]=ent.getName();
        objects[1]=ent.getWorkingLife();
        objects[2]=ent.getPersonalProfile();
        objects[3]=ent.getGraduateSchool();
        int i = JdbcUtil.CRUData(sql, objects);
        return i;
    }


    /**
     * 编辑商品信息的方法
     * @return
     */
    @Override
    public int EntEdit(Ent ent) {
        String sql="update enterpeiseTalent set " +
                "name=?,workingLife=?,personalProfile=?,graduateSchool=? where id=?";
        Object[] objects = new Object[5];
        objects[0]=ent.getName();
        objects[1]=ent.getWorkingLife();
        objects[2]=ent.getPersonalProfile();
        objects[3]=ent.getGraduateSchool();
        objects[4]=ent.getId();
        int i = JdbcUtil.CRUData(sql, objects);
        return i;
    }
}
